package fitnesshub.controller.member;

import fitnesshub.pojo.dto.AddConsumptionRecordDTO;
import fitnesshub.pojo.entity.ConsumptionRecord;
import fitnesshub.pojo.vo.MemberConsumptionRecordVO;
import fitnesshub.result.Result;
import fitnesshub.service.ConsumptionRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员消费记录
 */
@RestController
@Slf4j
@RequestMapping("/member/consumption")
public class MemberConsumptionRecordController {
    @Autowired
    private ConsumptionRecordService consumptionRecordService;

    /**
     * 添加消费记录
     * @param addConsumptionRecordDTO
     * @return
     */
    @PostMapping
    public Result save(@RequestBody AddConsumptionRecordDTO addConsumptionRecordDTO) {
        log.info("添加消费记录：{}", addConsumptionRecordDTO);
        consumptionRecordService.addConsumptionRecord(addConsumptionRecordDTO);
        return Result.success();
    }

    /**
     * 根据用户id查消费记录
     * @param memberId
     * @return
     */
    @GetMapping("/{memberId}")
    public Result<List<MemberConsumptionRecordVO>> getById(@PathVariable Integer memberId) {
        log.info("根据用户id查消费记录：{}", memberId);
        List<MemberConsumptionRecordVO> consumptionRecords = consumptionRecordService.getById(memberId);
        return Result.success(consumptionRecords);
    }
}
